package beans;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

public class lenguaje {
    private static String locale = Locale.getDefault().getDisplayLanguage();
    private List<SelectItem> idiomas;

    public lenguaje() {
        super();
        idiomas = new ArrayList<SelectItem>();
        idiomas.add(new SelectItem("es"));
        idiomas.add(new SelectItem("en"));
    }


    public void cambiarlenguaje(ValueChangeEvent valueChangeEvent) {

        System.out.println(Locale.getDefault().getDisplayLanguage());
        String local = (String)valueChangeEvent.getNewValue();
        FacesContext fc = FacesContext.getCurrentInstance();
        String pais = "";
        if (local.equals("es")) {
            pais = "ES";
        } else {
            pais = "UK";
        }
        fc.getViewRoot().setLocale(new Locale(local, pais));        
    }

    public List<SelectItem> getidiomas() {
        return idiomas;
    }
}
